package jp.sourceforge.akjrcp.ffmpeg;

import jp.sourceforge.akjrcp.ui.GenericParameters;
import jp.sourceforge.akjrcp.ui.GenericParametersFFMpegPreference;

public class FFMpegGenericParameters extends GenericParameters{

	public void setVideoCodec(String video_codec) {
		set(FFMpegOptions.OPTION_VIDEO_CODEC, video_codec);
	}

	public void setVideoSize(int width, int height) {
		set(FFMpegOptions.OPTION_VIDEO_SIZE, width+"x"+height);
	}

	public void setVideoBitrate(int videoBitrate) {
		set(FFMpegOptions.OPTION_VIDEO_BITRATE, ""+videoBitrate+"k");
	}

	public void setAudioBitrate(int audioBitrate) {
		set(FFMpegOptions.OPTION_AUDIO_BITRATE, ""+audioBitrate+"k");
	}

	public void setAudioChannel(int audioChannel) {
		set(FFMpegOptions.OPTION_AUDIO_CHANNEL, ""+audioChannel);
	}

	public void setAudioRate(int audioRate) {
		set(FFMpegOptions.OPTION_AUDIO_RATE, ""+audioRate);
	}

	public void setAspectRatio(String aspectRatio) {
		set(FFMpegOptions.OPTION_VIDEO_ASPECT, ""+aspectRatio);
	}

	public void setFormat(String format) {
		set(FFMpegOptions.OPTION_FORMAT,format);
	}

	/**
	 * extension is special value
	 * @param extension
	 */
	public void setExtension(String extension) {
		set(GenericParametersFFMpegPreference.EXTENSION,extension);
	}

	public void setAudioCodec(String audio_codec) {
		set(FFMpegOptions.OPTION_AUDIO_CODEC, audio_codec);
		
	}

	public void setCoder(String coder) {
		set(FFMpegOptions.OPTION_CODER,coder);
	}

	public void setFlags(String[] flags) {
		String v="";
		for (int i = 0; i < flags.length; i++) {
			v+=flags[i];
		if(i!=flags.length-1){
			v+="+";
		}
		}
		set(FFMpegOptions.OPTION_FLAGS,v);
	}

	public void setLevel(int level) {
		set(FFMpegOptions.OPTION_LEVEL,""+level);
	}
	
	/**
	 * never set null
	 */
	public void set(String key,String value){
		if(value==null){
			value="";
		}
		super.set(key,value);
	}
	
	private String getOptionValue(String key){
		String v=getParameters().get(key);
		if("".equals(v)){
			return null;
		}else{
			return v;
		}
	}
	public int  getLevel() {
		int level=0;
		String levelValue=getOptionValue(FFMpegOptions.OPTION_LEVEL);
		if(levelValue!=null){
			return Integer.parseInt(levelValue);
		}
	return level;
	}

	public void setVtag(String vtag) {
		set(FFMpegOptions.OPTION_VTAG,""+vtag);
	}

	public void setMaxRate(int maxrate) {
		set(FFMpegOptions.OPTION_MAXRATE,""+maxrate+"k");
	}

	public void setBufSize(int bufsize) {
		set(FFMpegOptions.OPTION_BUFSIZE,""+bufsize+"k");
	}

}
